package com.taptech.doufu.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by longsiyang on 16/4/26.
 */
public class TimeUtils234
{
    /**
     * 比较两个时间戳，是否在同一天
     */
    public static boolean compareTime(String t1, String t2)
    {
        try
        {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd");
            Date t1Date = new Date(Long.parseLong(t1) * 1000);
            String t1Time = formatter.format(t1Date);

            Date t2Date = new Date(Long.parseLong(t2) * 1000);
            String t2Time = formatter.format(t2Date);
            return t1Time.equals(t2Time);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 获取想要的时间格式
     */
    public static String getChineseRuleTime(String t1)
    {
        SimpleDateFormat sdf=null;
        try
        {
            Date waitCompareDate = new Date(Long.parseLong(t1) * 1000);
            Date nowTime = new Date(System.currentTimeMillis());
            if((waitCompareDate.getYear()==nowTime.getYear())){
                if(waitCompareDate.getMonth()==nowTime.getMonth()){
                    if((nowTime.getDay()==waitCompareDate.getDay())){
                        return "今天";
                    }else if(nowTime.getDay()==(waitCompareDate.getDay()+1)){
                        return "昨天";
                    }else{
                        sdf = new SimpleDateFormat("MM月dd日");
                        return sdf.format(waitCompareDate);
                    }
                }else{
                    sdf = new SimpleDateFormat("MM月dd日");
                    return sdf.format(waitCompareDate);
                }
            }else{
                sdf = new SimpleDateFormat("yyyy年MM月dd日");
                return sdf.format(waitCompareDate);
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        }

        return "时间格式不对";
    }
}
